package util;

import java.sql.Connection;

public class TransationUtil {
	
	public static void beginTransation() throws Exception{
		Connection conn = DBUtil.getConnction();
		conn.setAutoCommit(false);
		System.out.println("事务开始");
	}
	//先用抛出异常方法，判断会出现哪些重复提交的异常
	public static void commit() throws Exception{
		Connection conn = DBUtil.getConnction();
		conn.commit();
		System.out.println("提交事务");
	}
	/*正确提交的方法
	public static void commit() throws Exception{
		try{
			Connection conn = DBUtil.getConnction();
			conn.commit()
		}catch(Exception e){
		}
	}
	*/
	public static void rollback() throws Exception{
		Connection conn = DBUtil.getConnction();
		conn.rollback();
		System.out.println("回滚事务");
	}
	/*正确回滚的方法
	public static void rollback() throws Exception{
		try{
			Connection conn = DBUtil.getConnction();
			conn.rollback();
		}catch(Exception e){
		}
	}
	*/
}
